function  [tracks,nextId] = createNewTracks(tracks, unassignedDetections, centroids, bboxes, obj_features, param_kf, nextId, frame_idx)
% Create new tracks from unassigned detections. Assume that any unassigned
% detection is a start of a new track. In practice, you can use other cues
% to eliminate noisy detections, such as size, location, or appearance.
	centroids = centroids(unassignedDetections, :);
	bboxes = bboxes(unassignedDetections, :);

	for i = 1:size(centroids, 1)

		centroid = centroids(i,:);
		bbox = bboxes(i, :);
		obj_feature = obj_features(i);

		% Create a Kalman filter object.
		kalmanFilter = configureKalmanFilter(param_kf.motionModel, ...
		  centroid, param_kf.initialEstimateError, ...
		  param_kf.motionNoise, param_kf.measurementNoise);

		% Create a new track.
		newTrack = struct(...
			'id', nextId, ...
			'bbox', bbox, ...
			'traj_rec', centroid, ...
			'bbox_rec', bbox, ...
			'kalmanFilter', kalmanFilter, ...
			'age', 1, ...
			'appear_frame', frame_idx, ...
			'obj_feature', obj_feature, ...
			'state', "normal", ...
			'totalVisibleCount', 1, ...
			'consecutiveInvisibleCount', 0);

		% Add it to the array of tracks.
		tracks(end + 1) = newTrack;

		% Increment the next id.
		nextId = nextId + 1;
	end
end